<template>
  <div class="music-wrapper mb">
    <div class="search">
      <van-search
        v-model="searchData"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
      >
        <template #action>
          <van-field
            readonly
            clickable
            name="picker"
            :value="value"
            placeholder="分类"
            right-icon="arrow-down"
            @click="showPicker = true"
          />
          <van-popup v-model="showPicker" position="bottom">
            <van-picker
              show-toolbar
              :columns="columns"
              @confirm="onConfirm"
              @cancel="showPicker = false"
            />
          </van-popup></template>
      </van-search>
      <div class="hot">
        <van-tag v-for="i in hots" :key="i.id" type="success">{{ i.first }}</van-tag>
      </div>
    </div>
    <div class="swipe">
      <swipe />
    </div>
    <div class="list">
      <tab />
    </div>
  </div>
</template>

<script>
import tab from './tab'
import swipe from './swipe'
import { mapActions } from 'vuex'
export default {
  components: { swipe, tab },
  data() {
    return {
      searchData: '',
      value: '单曲',
      columns: ['单曲', '歌单', 'MV'],
      showPicker: false,
      hots: []
    }
  },
  created() {
    this.getHot().then(res => {
      console.log(res)
      if (res.data.code === 200) {
        this.hots = res.data.result.hots
      }
    })
  },
  methods: {
    onSearch() {
      console.log(27)
    },
    onConfirm(value) {
      this.value = value
      this.showPicker = false
    },
    ...mapActions(['getHot'])
  }
}
</script>

<style lang="scss" scoped>
.music-wrapper {
  width: 100%;
  .hot {
    width: 100%;
    height: 30px;
    line-height: 30px;
    overflow: auto;
    white-space: nowrap;
    .van-tag {
      margin: 0 5px;
    }
  }
  .swipe {
    margin-top: 10px;
  }
}
.van-field {
  width: 60px;
}
</style>
